package com.scanner;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Paint.Style;
import android.view.View;

public class TiltView extends View {
	TiltDownView downView;
	TiltUpView upView;
	TiltLeftView leftView;
	TiltRightView rightView;
	private Paint paint = new Paint();
	private String tiltText = "Tilt!";
	
	boolean down = false;
	boolean up = false;
	boolean left = false;
	boolean right = false;
	
	public TiltView(Context context) 
	{
		super(context);
		downView = new TiltDownView(context);
		upView = new TiltUpView(context);
		leftView = new TiltLeftView(context);
		rightView = new TiltRightView(context);		

		paint.setStrokeWidth(2);
		paint.setARGB(200, 250,250,250);
		paint.setStyle(Style.FILL); 
		paint.setTextSize(100); 

		setWillNotDraw(false);
	}
	
	public void Clear()
	{
		setPositions(false, false, false, false);
	}
	
	private void setPositions(boolean down, boolean up, boolean left, boolean right)
	{
		this.down = down;
		this.up = up;
		this.right = right;
		this.left = left;
	}
	
	public void	UpdatePosition(MoveActions action)
	{
		switch (action) {
		case TILT_DOWN:
			setPositions(false, true,false,false);
			break;
		case TILT_UP:
			setPositions(true,false,false,false);
			break;
		
		case TILT_LEFT:
			setPositions(false,false,false, true);
			break;
		
		case TILT_RIGHT:
			setPositions(false,false,true, false);
			break;
		
		case DONT_TILT:
			setPositions(false,false,false,false);
			break;
		case MOVE_DOWN:
			setPositions(false, true,false,false);
			break;
		case MOVE_UP:
			setPositions(true, false,false,false);
			break;
		
		case MOVE_LEFT:
			setPositions(false,false,false, true);
			break;
		
		case MOVE_RIGHT:
			setPositions(false,false,true, false);
			break;
		
		case DONT_MOVE:
			setPositions(false,false,false,false);
			break;

		default:
			setPositions(false,false,false,false);
			break;
		}
	}
	
	public void onDraw(Canvas canvas)
	{
		int x = 600;
		int y = 470;
		if (down)
		{
			downView.draw(canvas);
			canvas.drawText(tiltText, x, y, paint);
		}
		if (up)
		{
			upView.draw(canvas);
			canvas.drawText(tiltText, x, y, paint);
		}
		if (left)
		{
			leftView.draw(canvas);
			canvas.drawText(tiltText, x, y, paint);
		}
		if (right)
		{
			rightView.draw(canvas);
			canvas.drawText(tiltText, x, y, paint);
		}		
	}
}
